<?php 

/* ------------------------------------------------------------
 * Page: Selected Flights
 * Author: Gustavo Lozano & Fredrik Kronander
 * Description: Page where the user select the flights and the seats with its option
 * 
 **------------------------------------------------------------*/

?>



<script type="text/javascript">
<!--

//-->

$(document).ready(
	function ()
	{
		$("#0").hide();
		$("#1").hide();
		$("#2").hide();
		$("#3").hide();
		$("#4").hide();
		
		function countChecked()
		{
		    var n = $("input:checked#seat").length;
		    $("#counts").text(n + (n <= 1 ? " is" : " are") + " checked!"); 
		 }

		countChecked();
		$(":checkbox").click(countChecked);
	});


function check_submit()
{
	var n = $("input:checked#seat").length;

	if(n>0)
		return true;
	else
	{
		alert("Need to select at least 1 seat");
		return false;
	}		
}

function show_options(option)
{
	var get = "#"+option;
	var selector = "#S"+option+">input:checked";
	var unchecked = "#"+option+">input:checked";
	if($(selector).length>0)
	{
		$(get).show();	
	}
	else
	{
		$(unchecked).attr('checked', false);
		$(get).hide();
			
	}
}

</script>

<?php 
	
	require_once 'source/UtsAirs.php';	
	require_once 'source/Flight.php';
	
	$utsAirs = new UtsAirs();
	$selected = $_REQUEST["flightNo"];
?>

Selected Flights: 
<br><br>

<form action="index.php" onsubmit="return check_submit()">

<input type="hidden" name="flightNo" value=<?php echo "'".$selected."'";?>/>
<input type="hidden" name="content" value="YourBookings" />

<?php

		$flightsSearched = $utsAirs -> getFlight($selected);
?>

		From: <?php echo $flightsSearched->fromCity;?><br/>
		To: <?php echo $flightsSearched->toCity;?><br/>
				
		<table width="100%" align="left" id="tableSelected">
		<?php 
			for($i = 0; $i < 5 ; $i++)
			{	
		?>
			<tr >
					
					<td>
					<div id=<?php echo "S".$i?>>
						<input type="checkbox" onclick=<?php echo "show_options($i)"?> id="seat" name=<?php echo "'".$i."[]'" ?> value=<?php echo "'".CHECKED."'"?>/>Seat <?php echo $i+1?>
					</div>
					</td>
					<td>
						<div id=<?php echo $i?>>
							<input type="checkbox" name=<?php echo "'".$i."[]'" ?> value=<?php echo "'".CHILDREN."'"?> id="children"/>Children
							<input type="checkbox" name=<?php echo "'".$i."[]'" ?> value=<?php echo "'".INVALID."'"?> id="invalid"/>Invalid
							<input type="checkbox" name=<?php echo "'".$i."[]'"?> value=<?php echo "'".SPECIAL_DIET."'"?> id="specialDiet"/> Special Diet
						</div>
					</td>
					
			</tr>
			
		<?php 
			}
		?>
		</table>
		
<div id="counts"></div>
<input type="submit" value="Add to Bookings">

</form>